#coding:utf-8
'''
Created on 2019年3月13日

@author: wps
'''

from app import db
from app.admin.admin_view import admin
from app.models.model import ArticleList
from wtforms.fields.core import SelectField
from flask_admin.contrib.sqla.view import ModelView
from flask_login import current_user


class ArticleModelView(ModelView):

    def is_accessible(self):
        """是否可见权限控制
        """
        if not current_user.is_authenticated:
            return False
        if self.model.__tablename__=="flask_admin":
            return current_user.user_type
        return current_user.is_authenticated
    
class ArticleModelViewClo(ModelView):
    
        
    column_labels = dict(
        id=u"ID",
        title=u'标题',
        content=u"内容",
        source=u"来源",
        create_time=u"创建时间"
        )
    
    form_overrides = dict(user_type=SelectField)
    
#     form_args = dict(
#         user_type=dict(
#           choices=[("0", '普通管理'), ("1", '超级管理员')],
#           validators = []
#         )
#     )
admin.add_view(ArticleModelViewClo(ArticleList,db.session,name=u'文章信息'))